package com.lzh.seatrend.config.datasource;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;

import java.util.Properties;

@Configuration
// 因为MapperScannerConfigurer执行的比较早，所以必须有下面的注解
@AutoConfigureAfter(MybatisConfig.class)
public class MybatisMapperScannerConfig {

    private static final String SqlSessionFactory = "sqlSessionFactory";
    private static final String BasePackage = "com.lzh.springsecurity.mapper";

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer(){
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName(SqlSessionFactory);
        mapperScannerConfigurer.setBasePackage(BasePackage);
        Properties properties = new Properties();
        properties.setProperty("mappers","com.lzh.springsecurity.common.dao.BaseMapper");
        properties.setProperty("notEmpty","false");
        properties.setProperty("IDENTITY","ORACLE");
        mapperScannerConfigurer.setProperties(properties);
        return mapperScannerConfigurer;
    }
}
